#ifndef INSTRUMENT_LABELS_H
#define INSTRUMENT_LABELS_H
#include <ft2build.h>
#include FT_FREETYPE_H

#include "Drawer.h"
#include "MLObj.h"
#include "Stream.h"

struct _Text {
	GLuint fbo;
	GLuint texture;
};

class _InstrumentLabel {
public:
	_InstrumentLabel(
		FT_Face& font,
		int frame_size_x, int frame_size_y,
		size_t instruments_total_num,
		size_t instrument_index,
		std::string name,
		Color color,
		uint8_t alpha,
		uint32_t font_size,
		float line_spacing,
		GLuint glsl
	);
	_Text get_frame();

private:
	MLFrame _frame;
	static Location _calculate_text_size(FT_Face& font, std::string name);
	static std::vector<uint32_t> _utf8_to_codepoints(const std::string str);
	static _Text drawText(uint8_t* text_bitmap, int frame_size_x, int frame_size_y, GLuint shader_program);

	_Text _text;
};

class InstrumentLabels :public MLObj {
public:
	InstrumentLabels(
		int frame_size_x, int frame_size_y,
		double frame_rate,
		std::vector<VelocityStream>& streams,
		uint32_t font_size,
		std::string font_path,
		int32_t font_index,
		float line_spacing,
		Color color,
		uint8_t alpha,
		FT_Library font_library
	);
	void get_frame(size_t frame_index, MLFrame& frame);

private:
	MLFrame _frame;
	GLuint _mix_glsl;
};
#endif
